﻿using HDW_Migrate.Resources;
using HDW_Migrate.Extensions;
using Microsoft.EntityFrameworkCore;
using HDW_Migrate.Db.Entities;

namespace HDW_Migrate.Db;

/// <summary>
/// 老 RIS 数据库上下文
/// </summary>
public class RisDbContext: DbContext
{
    /// <summary>
    /// 检查单
    /// </summary>
    public DbSet<Order> Order { get; set; }
    /// <summary>
    /// 就诊信息
    /// </summary>
    public DbSet<Visit> Visit { get; set; }
    /// <summary>
    /// 报告单
    /// </summary>
    public DbSet<Report> Report { get; set; }
    /// <summary>
    /// 检查项
    /// </summary>
    public DbSet<Procedure> Procedure { get; set; }
    /// <summary>
    /// 患者
    /// </summary>
    public DbSet<Patient> Patient { get; set; }
    /// <summary>
    /// 设备类型
    /// </summary>
    public DbSet<Modality> Modality { get; set; }
    /// <summary>
    /// 设备
    /// </summary>
    public DbSet<Device> Device { get; set; }
    /// <summary>
    /// 检查项目
    /// </summary>
    public DbSet<CheckItem> CheckItem { get; set; }
    /// <summary>
    /// 危重值
    /// </summary>
    public DbSet<Critical> Critical { get; set; }
    /// <summary>
    /// 医院
    /// </summary>
    public DbSet<Hospital> Hospital { get; set; }
    /// <summary>
    /// 患者身份
    /// </summary>
    public DbSet<PatientIdentity> PatientIdentity { get; set; }
    /// <summary>
    /// 费用类别
    /// </summary>
    public DbSet<ChargeType> ChargeType { get; set; }
    /// <summary>
    /// 传染病检查
    /// </summary>
    public DbSet<InfectionResult> InfectionResult { get; set; }
    /// <summary>
    /// 尿素呼气试验(超声内镜使用)
    /// </summary>
    public DbSet<HpTestResult> HpTestResult { get; set; }
    /// <summary>
    /// 科室
    /// </summary>
    public DbSet<Department> Department { get; set; }
    /// <summary>
    /// 医生
    /// </summary>
    public DbSet<Staff> Staff { get; set; }
    /// <summary>
    /// 部位
    /// </summary>
    public DbSet<BodyPart> BodyPart { get; set; }
    /// <summary>
    /// 报告操作事件
    /// </summary>
    public DbSet<ReportEvent> ReportEvent { get; set; }
    /// <summary>
    /// 检查类型
    /// </summary>
    public DbSet<CheckType> CheckType { get; set; }
    /// <summary>
    /// 申请单附件
    /// </summary>
    public DbSet<OrderAttachment> OrderAttachment { get; set; }
    /// <summary>
    /// 预约日志
    /// </summary>
    public DbSet<OrderScheduleLog> OrderScheduleLog { get; set; }

    /// <inheritdoc />
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        var setting = SystemSettingDto.Read();
        if (setting.SourceDbConnection.IsEmpty()) throw new Exception("未设置老 RIS 数据库链接！");
        optionsBuilder.UseSqlServer(setting.SourceDbConnection);
    }
}
